<?php
namespace App\Lib;

use App\Models\Article;

class Export
{
	private $article;
	public function __construct($article, $press=false)
	{
		$this->article = $article;

		$this->press = $press;
	}
	
	public function getBibTex()
	{
		$article = $this->article;
		if ($this->press) {
		return <<<EOF
@article{:{$article->page_start},
author = {{$article->getPureAuthor()}},
title = {{$article->title}},
publisher = {Zoological Research},
year = {{$article->issue->year}},
journal = {Zoological Research},
volume = 0,
number = 0,
eid = 0,
numpages = {},
pages = 0,
keywords = {{$article->keywords}},
url = {{$article->getUrl()}},
doi = {{$article->doi_number}}
}


EOF;
		}

		return <<<EOF
@article{:{$article->page_start},
author = {{$article->getPureAuthor()}},
title = {{$article->title}},
publisher = {Zoological Research},
year = {{$article->issue->year}},
journal = {Zoological Research},
volume = {{$article->issue->volume}},
number = {$article->issue->issue},
eid = {{$article->page_start}},
numpages = {},
pages = {{$article->page_start}},
keywords = {{$article->keywords}},
url = {{$article->getUrl()}},
doi = {{$article->id_doi}}
}


EOF;
	}

	public function getEndNote()
	{
		$article = $this->article;

		if ($this->press) {
		return <<<EOF
%A {$article->getPureAuthor()}
%T {$article->title}
%0 Journal Article
%D 0
%J Zoological Research
%R {$article->doi_number}
%P 0-0
%V 0
%N 0
%U {{$article->getUrl()}}
%8 {date($article->publish_date)}
%X {$article->abstract}.&nbsp;


EOF;
		}

		return <<<EOF
%A {$article->getPureAuthor()}
%T {$article->title}
%0 Journal Article
%D {$article->issue->year}
%J Zoological Research
%R {$article->id_doi}
%P {$article->page_start}-{$article->page_end}
%V {$article->issue->volume}
%N {$article->issue->issue}
%U {{$article->getUrl()}}
%8 {date($article->publish_date)}
%X {$article->abstract}.&nbsp;


EOF;
	}

	//reference manager
	public function getReferenceManager()
	{
		$article = $this->article;

		if ($this->press) {
			$volume = 0;
			$issue = 0;
			$doi = $article->doi_number;
		} else {
			$volume = $article->issue->volume;
			$issue = $article->issue->issue;
			$doi = $article->id_doi;
		}

		return <<<EOF
TY  - Zoological Research
A1  - {$article->getPureAuthor()}
T1  - {$article->title}
Y1  - {date($article->publish_date)}
JF  - Zoological Research
JO  - Zoological Research
SP  - {$article->page_start}
EP  - {$article->page_end}
VL  - {$volume}
IS  - {$issue}
UR  - {$article->getUrl()}
N1  - {$doi}
ER  - 


EOF;
	}

	public function getProcite()
	{
		$article = $this->article;
		if ($this->press) {
		return <<<EOF
TY  - Zoological Research
A1  - {$article->getPureAuthor()}
T1  - {$article->title}
Y1  - {date($article->publish_date)}
JF  - Zoological Research
JO  - Zoological Research
SP  - 0
EP  - 0
VL  - 0
IS  - 0
UR  - {$article->getUrl()}
N1  - {$article->doi_number}
ER  - 


EOF;
		}
		return <<<EOF
TY  - Zoological Research
A1  - {$article->getPureAuthor()}
T1  - {$article->title}
Y1  - {date($article->publish_date)}
JF  - Zoological Research
JO  - Zoological Research
SP  - {$article->page_start}
EP  - {$article->page_end}
VL  - {$article->issue->volume}
IS  - {$article->issue->issue}
UR  - {$article->getUrl()}
N1  - {$article->id_doi}
ER  - 


EOF;
	}


	public function getRefWorks()
	{
		$article = $this->article;

		return <<<EOF
RT Journal
T1 {$article->title}
A1 {$article->getPureAuthor()}
PB Zoological Research
FD {date($article->publish_date)}
YR {$article->issue->year}
JF Zoological Research
JO Zoological Research
VO {$article->issue->volume}
IS {$article->issue->issue}
SP {$article->page_start}
DO {$article->id_doi}
K1 {$article->keywords}
LK {$article->getUrl()}


EOF;
	}
}